package com.wisdudu.blank.ui.login;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;

import com.wisdudu.blank.data.Injection;
import com.wisdudu.blank.data.repo.UserRepo;
import com.wisdudu.blank.ui.home.HomeActivity;
import com.wisdudu.frame.base.BaseActivity;

/**
 * Created by qyf on 2016/10/9.
 */

public class SplashActivity extends BaseActivity {
    private Handler mHandler;
    private Runnable mRunnable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_splash);
        mHandler = new Handler();
        mHandler.postDelayed(mRunnable = this::checkLoginState, 1000);
    }

    private void checkLoginState() {
        UserRepo userRepo = Injection.provideUserRepo();
        if (userRepo.isFirstLanuncher()) {
            startActivity(new Intent(this, GuideActivity.class));
            finish();
        } else {
            if (userRepo.isLogin()) {
//                ICVSSUserModule.getInstance(this).getIcvss().equesLogin(this, ICVSSUserModule.DISTRIBUTE_URL, ICVSSUserModule.USERNAME, ICVSSUserModule.APPKEY);
                startActivity(new Intent(this, HomeActivity.class));
                finish();
            } else {
                startActivity(new Intent(this, LoginActivity.class));
                finish();
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mHandler.removeCallbacks(mRunnable);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        if (mHandler != null) {
            mHandler.removeCallbacks(mRunnable);
        }
    }
}
